import { store } from "@/store/index";

/**
 * @description 判断当前用户是否有权限
 * @param {*} value 用户权限数组或字符串、数值,例:['admin']
 */
export function hasPermission(value) {
  // Visible by default
  if (!value) {
    return true;
  }
  // 获取登录用户权限信息
  const { userInfo } = store.state.user;
  const { roles } = userInfo;
  if (!Array.isArray(value)) {
    return roles.includes(value);
  }
  // value是数组
  return value.some((item) => roles.includes(item));
}
